package jltx.fragmentpageframework.simple.adapter;

import android.graphics.Color;
import android.view.View;

import com.xq.recyclerviewlib.CommonQuickAdapter;
import com.xq.recyclerviewlib.CommonViewHolder;

import java.util.List;

import jltx.fragmentpageframework.R;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2017/06/07.
 */

public class MenuListAdapter extends CommonQuickAdapter<String>{
    private int mLastCheckedPosition = -1;

    public MenuListAdapter(List<String> mData) {
        super(R.layout.menu_simple_shop_item, mData);
    }

    @Override
    protected void convert(CommonViewHolder commonViewHolder, String item,int position) {
        if(position == mLastCheckedPosition){ //选中
            commonViewHolder.setVisibility(R.id.line, View.INVISIBLE);
            commonViewHolder.itemView.setBackgroundResource(R.color.bg_app);
            commonViewHolder.setTextColor(R.id.tv_name,mContext.getResources().getColor(R.color.colorPrimary));
        }else {
            commonViewHolder.setVisibility(R.id.line, View.VISIBLE);
            commonViewHolder.itemView.setBackgroundColor(Color.WHITE);
            commonViewHolder.setTextColor(R.id.tv_name,Color.BLACK);
        }
        commonViewHolder.setText(R.id.tv_name,item);

    }

    @Override
    public void setData(List<String> mData) {
        super.setData(mData);
    }

    public void setItemChecked(int position){
        if(position != mLastCheckedPosition){
            mLastCheckedPosition = position;
            notifyDataSetChanged();
        }
    }
}
